package se.liu.johfa428.game.objects.intro;


import java.awt.Color;

import se.liu.oschi129.animation.animationspace.AnimationSpace;
import se.liu.oschi129.level.levelspace.LevelSpace;
import se.liu.oschi129.world.interfaces.InputAction;
import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.model.WorldInput;
import se.liu.oschi129.world.objects.WorldMovableObject;

public class ObjectMenuLogo extends WorldMovableObject implements InputAction {

	private double xTo, yTo;

	private boolean done, goToNext = false;
	private boolean firstTimePressed = true;
	
	/**
	 * Use this initializer when you want the logo to move in to the frame 
	 * from above and the centering it self in the window
	 * @param viewWidth
	 * The width of the view window
	 * @param viewHeight
	 * The height of the view window
	 */
	public ObjectMenuLogo(double viewWidth, double viewHeight) {
		super(Type.SOFT, AnimationSpace.get("img_logo01"),true ,viewWidth/2 - 175/2 , -148/2 ,351/2 ,148/2);
		setDepth(-1);
		this.xTo = viewWidth/2 - 175/2;
		this.yTo = viewHeight/2 - 74/2;
		this.moveToPosition(xTo, yTo, 1);
	}

	public void setCenter (){
		this.setX(this.xTo);
		this.setY(this.yTo);
	}

	public boolean getDone(){
		return this.done;
	}

	public void setDone(boolean done){
		this.done = done;
	}
	
	public void performInputAction(WorldInput input) {
		if (input.jumpDown())
			if (firstTimePressed){
				setX(xTo);
				setY(yTo);
				firstTimePressed = false;
			}else{
				goToNext = true;
			}
	}
	
	
	@Override public void performStepAction(World world) {
		super.performStepAction(world);
		if (Math.sqrt((xTo - getX()) * (xTo - getX()) + (yTo - getY()) * (yTo - getY())) <= 2 && !getDone()) {
			setVerticalSpeed(0);
			setHorizontalSpeed(0);
			setX(xTo);
			setY(yTo);
			if (!getDone()){
				//starts the next sequence
				ObjectMenuBackground BG = new ObjectMenuBackground();
				ObjectWhiteSpace white = new ObjectWhiteSpace (0,0, 480, 640, 100, Color.WHITE, -4);
				
				white.setVisible(true);	

				world.addObjectSynchronized(BG);
				world.addObjectSynchronized(white);	
				
				setDone(true);
			}
		}
		if(goToNext){	
	
			world.clearSynchronized();		
			LevelSpace.get("level00_levelselection").createWorld(world,null);
			
			goToNext = false;
		}	
		
	}
}
